package com.example.bookshop.controller.user;

import com.example.bookshop.entity.BaseGoods;
import com.example.bookshop.entity.Goods;
import com.example.bookshop.result.Result;
import com.example.bookshop.service.user.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
public class GoodsController {
    @Autowired
    GoodsService goodsService;
    //返回所有图书
    @GetMapping ("api/getListGoods")
    public List<BaseGoods> getListGoods(){
        return goodsService.getListGoods();
    }
    //查询不同种类的书
    @RequestMapping("api/getCategoryGoods")
    public List<BaseGoods>getCategoryGoods(@RequestBody Goods goods){
        return goodsService.getCategoryGoods(goods.getCategory(),goods.getState());
    }
    //返回订单详细信息
    @RequestMapping("api/findGoodsDetail")
    public Goods findGoodsDetail(@RequestBody Goods goods){
        return goodsService.findGoodsDetail(goods.getId());
    }
    @RequestMapping("api/addGoods")
    public Result addGoods(@RequestBody Goods goods, HttpSession session){
        return goodsService.addGoods(goods,session);
    }
    //查找自己上架的商品
    @RequestMapping("api/findGoodsByMall")
    public List<BaseGoods>findGoodsByMall(HttpSession session){
        return goodsService.findGoodsByMall(session);
    }
    //修改商品信息
    @RequestMapping("api/modifyGoods")
    public Result modifyGoods(@RequestBody Goods goods){
        return goodsService.modifyGoods(goods);
    }
    //删除商品
    @RequestMapping("api/deleteGoods")
    public Result deleteGoods(@RequestBody Goods goods){
        return goodsService.deleteGoods(goods.getId());
    }

    //查找商品
    @RequestMapping("api/searchGoods")
    public List<BaseGoods>searchGoods(@RequestBody Goods goods){
        return goodsService.searchGoods(goods);
    }
}
